package com.alks.function.controller.task;

import com.alibaba.fastjson2.JSON;
import com.alks.common.aop.RedisLock;
import com.alks.common.service.RedisService;
import com.alks.entity.data.entity.PcCuttingSalary;
import com.alks.function.data.request.PcCuttingSalaryReq;
import com.alks.function.mapper.PcOrderHeadMapping;
import com.alks.function.mapper.finance.salary.SalaryFileCreationMapper;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author:hxl
 * @create: 2024-07-26 16:49
 * @Description:
 */
@Component
@Slf4j
public class PcCuttingSalaryTask {
    private static final String salary_redis = "salary-cutting-redis";
    @Autowired
    private SalaryFileCreationMapper salaryFileCreationMapper;
    @Autowired
    private RedisService redisService;

    @Scheduled(initialDelay = 0, fixedRate = 1000 * 60 * 60)
    @RedisLock(key = "task:PcCuttingSalaryTask.execute")
    public void execute(){
        try {
            PcCuttingSalaryReq req = new PcCuttingSalaryReq();
            req.setPageNum(1);
            req.setPageSize(40);
            PageHelper.startPage(req.getPageNum(), req.getPageSize(), false);
            List<PcCuttingSalary> list = salaryFileCreationMapper.getPcCuttingSalary(req);
            redisService.set(salary_redis, JSON.toJSONString(list));
        }catch (Exception e){
//            e.printStackTrace();
        }

    }

    @Autowired
    PcOrderHeadMapping pcOrderHeadMapping;

    @Scheduled(initialDelay = 0, fixedRate = 1000 * 60*60*24)
    @RedisLock(key = "task:PcCuttingSalaryTask.executeProdStatus")
    @Transactional
    public void executeProdStatus(){
        pcOrderHeadMapping.deleteProdStatus();
        pcOrderHeadMapping.updateProdStatus();
        //查询进度表订单号
    }
}
